package com.example.red_tea_house.moudle.LoginAndRegister.view;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.example.red_tea_house.R;
import com.example.red_tea_house.moudle.LoginAndRegister.controller.ForgetPasswordController;

public class ForgetPasswordAcitivity extends AppCompatActivity {
    private EditText register_phone_find_back_password;
    private EditText input_identifying_code_find_back_password;
    private EditText setting_password_find_back_password_1;
    private EditText setting_password_find_back_password_2;
    private Button getVertifyCodeInForgetPassword;
    private Button submit_find_back_password;
    private Button amend_the_password_success_return;
    private String str_phone;
    private String str_identifyCode;
    private String str_password1;
    private String str_password2;
    private int returncode;

    private ForgetPasswordController forgetPasswordController=new ForgetPasswordController();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.amend_the_password);

        bindItems();

        getVertifyCodeInForgetPassword.setOnClickListener((v)->{
            str_phone=register_phone_find_back_password.getText().toString();
            forgetPasswordController.getVertifycode(str_phone);
        });

        submit_find_back_password.setOnClickListener((v)->{
            getInputData();
            returncode=forgetPasswordController.resetpassword(str_phone,str_identifyCode,str_password1,str_password2);
            if(returncode==1){
                setContentView(R.layout.amend_the_password_succeessful);
                amend_the_password_success_return=findViewById(R.id.amend_the_password_success_return);
                amend_the_password_success_return.setOnClickListener((v1)->{ finish();
                });
            }
        });
    }

    private void bindItems(){
        register_phone_find_back_password=findViewById(R.id.register_phone_find_back_password);
        input_identifying_code_find_back_password=findViewById(R.id.input_identifying_code_find_back_password);
        setting_password_find_back_password_1=findViewById(R.id.setting_password_find_back_password_1);
        setting_password_find_back_password_2=findViewById(R.id.setting_password_find_back_password_2);
        getVertifyCodeInForgetPassword =findViewById(R.id.gain_identifying_code_find_back_password);
        submit_find_back_password=findViewById(R.id.submit_find_back_password);

    }
    private void getInputData(){
        str_phone=register_phone_find_back_password.getText().toString();
        str_identifyCode=input_identifying_code_find_back_password.getText().toString();
        str_password1=setting_password_find_back_password_1.getText().toString();
        str_password2=setting_password_find_back_password_2.getText().toString();
    }
}
